import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int[] a = new int[200005]; // 定义数组a，存储计算结果
        for (int i = 1; i < 200005; i++) {
            a[i] = a[i - 1] + solve(i);
        }

        int t = scanner.nextInt(); // 读取测试用例数量
        while (t > 0) {
            int n = scanner.nextInt(); // 读取每个测试用例中 n 的值
            System.out.println(a[n]);
            t--;
        }

        scanner.close();
    }

    public static int solve(int n) {
        int temp = 0;
        while (n != 0) {
            temp += n % 10;
            n /= 10;
        }
        return temp;
    }
}
